import {
	defineStore
} from 'pinia'
import {
	computed,
	ref
} from 'vue'

/*
 **使用uniapp的存储方案，此方案弃用
 */

const initState = {
	nickname: '',
	avatar: '',
	selectMchine: '',
}

export const useCurrentUserStore = defineStore(
	'user',
	() => {
		/*
		 **状态
		 */
		const userInfo = ref({
			...initState
		})


		/*
		 **方法
		 */
		const set_userInfo = (val) => {
			userInfo.value = val
		}

		const clear_userInfo = () => {
			userInfo.value = {
				...initState
			}
		}

		const set_selectMachine = (val) => {
			userInfo.value.selectMchine = val;
		}

		//判断是否已经登录
		const is_login = computed(() => !!userInfo.value.token);

		return {
			userInfo,
			set_userInfo,
			set_selectMachine,
			clear_userInfo,
			is_login,
		}
	}, {
		persist: true, //持久化
	},
)